
package com.kanjian.music.fragment;

import java.util.ArrayList;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;

import com.kanjian.music.R;
import com.kanjian.music.activity.BaseActivity;
import com.kanjian.music.activity.RankActivity;
import com.kanjian.music.adapter.MusicListListAdapater;
import com.kanjian.music.adapter.MusicianListListAdapater;
import com.kanjian.music.constants.IntentConstants;
import com.kanjian.music.constants.MusicListTypeConstants;
import com.kanjian.music.dialog.ShareDialog;
import com.kanjian.music.entity.Music;
import com.kanjian.music.entity.Musician;
import com.kanjian.music.entity.RankDetail;

public class MusicianListFragment extends BaseFragment {

    public static MusicianListFragment newInstance(ArrayList<Musician> musicianList) {
        Bundle b = new Bundle();
        b.putSerializable(IntentConstants.MUSICIANLIST, musicianList);
        MusicianListFragment f = new MusicianListFragment();
        f.setArguments(b);
        return f;
    }

    private View mRootView;

    private ArrayList<Musician> mMusicianList;

    private Button mBtn_share;

    private ListView mListView;

    private MusicianListListAdapater mListAdapater;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle b = getArguments();
        if (b != null) {
            mMusicianList = (ArrayList<Musician>) b.getSerializable(IntentConstants.MUSICIANLIST);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        initView(inflater);
        return mRootView;
    }

    private void initView(LayoutInflater inflater) {
        if (mRootView == null) {
            mRootView = inflater.inflate(R.layout.fragment_musician_list, null);
            mListView = (ListView) mRootView.findViewById(R.id.musicianlist_listview);
//            mBtn_share = (Button) mRootView.findViewById(R.id.musicianlist_controler_share);
//            mBtn_share.setOnClickListener(new OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (getActivity() instanceof RankActivity) {
//                        String rankName = null;
//                        switch (((RankActivity) getActivity()).mMusicListType) {
//                            case MusicListTypeConstants.MUSIC_LIST_TYPE_HOT:
//                                rankName = "24小时热门榜";
//                                break;
//                            case MusicListTypeConstants.MUSIC_LIST_TYPE_MONTH:
//                                rankName = "最近30天";
//                                break;
//                            case MusicListTypeConstants.MUSIC_LIST_TYPE_WEEK:
//                                rankName = "最近7天";
//                                break;
//                            case MusicListTypeConstants.MUSIC_LIST_TYPE_NEW:
//                                rankName = "新晋榜";
//                                break;
//                            default:
//                                rankName = "24小时热门榜";
//                                break;
//                        }
//                        ShareDialog.newInstance(rankName).show(getFragmentManager(), "");
//                    }
//                }
//            });
        }
        mListAdapater = new MusicianListListAdapater((BaseActivity) getActivity(), mMusicianList,
                mListView);
        mListView.setAdapter(mListAdapater);
    }

}
